<?php
declare (strict_types=1);

namespace app\exam\model\admin;

use app\common\model\BaseModel;
use think\model\concern\SoftDelete;

/**
 * Class ModuleExamination
 *
 * @package app\exam\model\admin
 */
class ModuleExamination extends BaseModel
{
    use SoftDelete;

    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'exam_module_examination';

    /**
     * 自动写入时间
     *
     * @var bool
     */
    protected $autoWriteTimestamp = true;

    /**
     * 定义表主键
     *
     * @var string
     */
    protected $pk = 'id';

    /**
     * 时间显示格式
     *
     * @var string
     */
    protected $dateFormat = 'Y-m-d H:i';

    /**
     * 试卷信息
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2021/2/4
     *
     * @return \think\model\relation\BelongsTo
     */
    public function paper()
    {
        return $this
            ->belongsTo(Paper::class, 'paper_id', 'id')
            ->append(['paper_type_text'])
            ->bind(['title', 'topic_count' => 'total_count', 'paper_type', 'paper_type_text', 'category', 'total_score'])
            ->removeOption('soft_delete')
            ->removeWhereField('mhm_id');
    }

    /**
     * 版块
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2021/5/6
     *
     * @return \think\model\relation\BelongsTo
     */
    public function module()
    {
        return $this
            ->belongsTo(Module::class, 'module_id', 'id')
            ->bind(['module_title' => 'title'])
            ->removeOption('soft_delete')
            ->removeWhereField('mhm_id');
    }

    /**
     * 试卷信息
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2021/2/4
     *
     * @return \think\model\relation\BelongsTo
     */
    public function paperTitle()
    {
        return $this
            ->belongsTo(Paper::class, 'paper_id', 'id')
            ->bind(['title'])
            ->removeOption('soft_delete')
            ->removeWhereField('mhm_id');
    }
}